<template>
    <div>
        <el-dialog v-dialogDrag title="关联企业" :visible="linkShow" width="40%" @close="dialogClose" :close-on-click-modal="false">
            <el-form ref="linkForm" :model="formFileds" :rules="rules" label-width="auto">
                <p>您所在的公司是</p>
                <el-form-item prop="companyName">
                    <el-input v-model="formFileds.companyName" readonly></el-input>
                </el-form-item>
                <!-- <el-form-item v-if="!able">
                    <el-button type="primary" @click="submitForm()" class="pull-right margin-l-25">确定
                    </el-button>
                    <el-button @click="dialogClose" class="pull-right">取消</el-button>
                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="relieve" class="pull-right">解除关联</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { correlation } from '@/api/systemManage/enterpriseMaage';
export default {
    //接受父组件
    props: {
        linkShow: {
            type: Boolean
        },
        linkData: {
            type: Array
        },
        record: {
            type: Object
        }
    },

    data () {
        return {
            able: false,
            tabledata: [],
            formFileds: {
                id: '',
                companyName: '',
            },
            rules: {
                companyName: [{ required: true, message: '请输入公司名称', trigger: 'blur,change' }]
            },
        }
    },
    methods: {
        dialogClose () {
            this.$emit('dialogClose')
        },
        relieve () {
            this.$confirm('解除关联会删除该公司以及下属子公司和分公司信息，确定要与当前公司解除关联吗？', '解除关联', {
                comfirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(() => {
                let companyId = this.formFileds.id
                let userId = localStorage.getItem('userId')
                let type = 1
                correlation({ companyId, userId, type }).then((res) => {
                    if (res) {
                        localStorage.removeItem('companyId')
                        this.$message.success('操作成功！')
                        this.$emit('Ok')
                        this.$emit('dialogClose')
                    }
                })
            })
        },
        // submitForm () {
        //     this.$refs.linkForm.validate((valid) => {
        //         if (valid) {
        //             if (this.linkData.length == 0) {
        //                 this.$message.error('请先添加母公司或子公司！')
        //             }
                    
        //         } else {
        //             return
        //         }
        //     });
        // },

    },
    mounted () {
        this.formFileds.companyName = this.record.companyName
        this.formFileds.id = this.record.companyId
        // if (this.record.companyId) {
        //     this.able = true
        // } else {
        //     this.able = false
        // }
    }
}
</script>

<style lang="less" scoped>

</style>